package com.have.blog.admin.redis.impl;


import com.have.blog.admin.constant.AdminRedisConstant;
import com.have.blog.admin.constant.RedisExpiredTime;
import com.have.blog.admin.redis.SystemConfigCacheService;
import com.have.blog.base.constant.BaseRedisConstant;
import com.have.blog.config.service.RedisService;
import com.have.blog.model.models.SystemConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

@Service
public class SystemConfigCacheServiceImpl implements SystemConfigCacheService {
    @Autowired
    private RedisService redisService;
    @Value("${redis.admin.database}")
    private String REDIS_KEY_DATABASE;

    @Override
    public SystemConfig getSystemConfig() {
        String key = REDIS_KEY_DATABASE + AdminRedisConstant.SEGMENTATION + BaseRedisConstant.SYSTEM_CONFIG;
        return (SystemConfig) redisService.get(key);
    }

    @Override
    public void setSystemConfig(SystemConfig systemConfig) {
        String key = REDIS_KEY_DATABASE + AdminRedisConstant.SEGMENTATION + BaseRedisConstant.SYSTEM_CONFIG;
        redisService.set(key, systemConfig, RedisExpiredTime.ONE_DAY.getDuration(), RedisExpiredTime.ONE_DAY.getTimeUnit());
    }

    @Override
    public void delSystemConfig() {
        String key = REDIS_KEY_DATABASE + AdminRedisConstant.SEGMENTATION + BaseRedisConstant.SYSTEM_CONFIG;
        redisService.del(key);
    }
}
